//--------------------------------------------------------------------------------------------
// Number Extensions
//
//


Number.prototype.toPaddedString = function (wholeLength, decimalLength) {
	var multiplier = Math.pow(10,decimalLength);
	var wholeNum = Math.floor(this).toString();
	var decNum = Math.round((this % 1.0) * multiplier);
	
	wholeNum = wholeNum.padLeft(wholeLength,'0');
	
	return (wholeLength>0 ? wholeNum : '') + (decimalLength>0 ? '.' + decNum : '');
}



//--------------------------------------------------------------------------------------------
// String Extensions
//
//


String.prototype.padLeft = function (toSize, padding) {
	if (!padding) padding = ' ';
	
	var s = this;
	
	while (s.length < toSize) {
		s = padding + s;
	}
	
	return s;
}

String.prototype.padRight = function (toSize, padding) {
	if (!padding) padding = ' ';
	
	var s = this;
	
	while (s.length < toSize) {
		s += padding;
	}
	
	return s;
}

String.prototype.left = function (size) {
	return this.substr(0,size);
}

String.prototype.right = function (size) {
	return this.substr(-size,size);
}

String.prototype.mid = function (start, length) {
	return (length) ? this.substr(start, length) : this.substr(start);
}



//--------------------------------------------------------------------------------------------
// Array Extensions
//
//

Array.prototype.append = function (newElement) {
	this[this.length] = newElement;
	return this;
}

Array.prototype.remove = function (oldElement) {
	var i, found = false;
	if (typeof(oldElement) == 'number') {
		found = true;
		i = oldEl;
	} else {
		for (i=0; i<this.length; i++) {
			if (this[i] == oldElement) { found = true; break; }
		}
	}
	
	if (found) {
		for (j=i; j<this.length-1; j++) {
			this[j] = this[j+1];
		}
		delete this[this.length-1];
		this.length = this.length - 1;
	}

	return oldElement;
}


Array.prototype.getIndex = function (refEl) {
	var i = this.length;
	for (var n=0; n<this.length; n++) {
		if (this[n] == refEl) {
			i = n;
			break;
		}
	}
	return i;
}

Array.prototype.clear = function () {
	for(var i=0; i < this.length; i++) delete this[i];
	this.length = 0;
}

Array.prototype.contains = function (el) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == el)
			return true;
	}
	return false;
}

LoadProgress.completeModule('Intrinsic');